home *** CD-ROM | disk | FTP | other *** search
- /**
- * Scout - The Amiga System Monitor
- *
- *------------------------------------------------------------------
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * You must not use this source code to gain profit of any kind!
- *
- *------------------------------------------------------------------
- *
- * @author Andreas Gelhausen
- * @author Richard Körber <rkoerber@gmx.de>
- */
-
- #include "system_headers.h"
-
- struct LowMemoryCallbackUserData {
- APTR ud_List;
- ULONG ud_Count;
- };
-
- static __asm __saveds LONG lowmemlist_con2func(register __a2 Object *obj, register __a1 struct NList_ConstructMessage *msg, register __a0 struct Hook *hook)
- {
- return AllocListEntry(msg->pool, msg->entry, sizeof(struct LowMemoryEntry));
- }
-
- MakeHook(lowmemlist_con2hook, lowmemlist_con2func);
-
- static __asm __saveds LONG lowmemlist_des2func(register __a2 Object *obj, register __a1 struct NList_DestructMessage *msg, register __a0 struct Hook *hook)
- {
- FreeListEntry(msg->pool, &msg->entry);
-
- return 0;
- }
-
- MakeHook(lowmemlist_des2hook, lowmemlist_des2func);
-
- static __asm __saveds LONG lowmemlist_dsp2func(register __a2 Object *obj, register __a1 struct NList_DisplayMessage *msg, register __a0 struct Hook *hook)
- {
- struct LowMemoryEntry *lme = (struct LowMemoryEntry *)msg->entry;
-
- if (lme) {
- msg->strings[0] = lme->lme_Address;
- msg->strings[1] = lme->lme_Name;
- msg->strings[2] = lme->lme_Type;
- msg->strings[3] = lme->lme_Pri;
- msg->strings[4] = lme->lme_Data;
- msg->strings[5] = lme->lme_Code;
- } else {
- msg->strings[0] = "Address";
- msg->strings[1] = "ln_Name";
- msg->strings[2] = "ln_Type";
- msg->strings[3] = "ln_Pri";
- msg->strings[4] = "is_Data";
- msg->strings[5] = "is_Code";
- msg->preparses[0] = MUIX_B;
- msg->preparses[1] = MUIX_B;
- msg->preparses[2] = MUIX_B;
- msg->preparses[3] = MUIX_B;
- msg->preparses[4] = MUIX_B;
- msg->preparses[5] = MUIX_B;
- }
-
- return 0;
- }
-
- MakeHook(lowmemlist_dsp2hook, lowmemlist_dsp2func);
-
- static LONG lowmemlist_cmp2colfunc( struct LowMemoryEntry *lme1,
- struct LowMemoryEntry *lme2,
- ULONG column )
- {
- LONG pri1, pri2;
-
- switch (column) {
- case 0: return stricmp(lme1->lme_Address, lme2->lme_Address);
- case 1: return stricmp(lme1->lme_Name, lme2->lme_Name);
- case 2: return stricmp(lme1->lme_Type, lme2->lme_Type);
- case 3: IsDec(lme1->lme_Pri, &pri1); IsDec(lme2->lme_Pri, &pri2); return pri2 - pri1;
- case 4: return stricmp(lme1->lme_Data, lme2->lme_Data);
- case 5: return stricmp(lme1->lme_Code, lme2->lme_Code);
- }
- }
-
- static __asm __saveds LONG lowmemlist_cmp2func(register __a2 Object *obj, register __a1 struct NList_CompareMessage *msg, register __a0 struct Hook *hook)
- {
- LONG cmp;
- struct LowMemoryEntry *lme1, *lme2;
- ULONG col1, col2;
-
- lme1 = (struct LowMemoryEntry *)msg->entry1;
- lme2 = (struct LowMemoryEntry *)msg->entry2;
- col1 = msg->sort_type & MUIV_NList_TitleMark_ColMask;
- col2 = msg->sort_type2 & MUIV_NList_TitleMark2_ColMask;
-
- if (msg->sort_type == MUIV_NList_SortType_None) return 0;
-
- if (msg->sort_type & MUIV_NList_TitleMark_TypeMask) {
- cmp = lowmemlist_cmp2colfunc(lme2, lme1, col1);
- } else {
- cmp = lowmemlist_cmp2colfunc(lme1, lme2, col1);
- }
-
- if (cmp != 0 || col1 == col2) return cmp;
-
- if (msg->sort_type2 & MUIV_NList_TitleMark2_TypeMask) {
- cmp = lowmemlist_cmp2colfunc(lme2, lme1, col2);
- } else {
- cmp = lowmemlist_cmp2colfunc(lme1, lme2, col2);
- }
-
- return cmp;
- }
-
- MakeHook(lowmemlist_cmp2hook, lowmemlist_cmp2func);
-
- static void ReceiveList( void (* callback)( struct LowMemoryEntry *lme, void *userData ),
- void *userData )
- {
- struct LowMemoryEntry *lme;
-
- if (lme = tbAllocVecPooled(globalPool, sizeof(struct LowMemoryEntry))) {
- if (SendDaemon("GetLowMemList")) {
- while (ReceiveDecodedEntry((UBYTE *)lme, sizeof(struct LowMemoryEntry))) {
- callback(lme, userData);
- }
- }
-
- tbFreeVecPooled(globalPool, lme);
- }
- }
-
- static void IterateList( void (* callback)( struct LowMemoryEntry *lme, void *userData ),
- void *userData )
- {
- if (CheckLibVersion(SysBase, 39, 0) == CLV_NEWER_OR_SAME) {
- struct MinList tmplist;
- struct LowMemoryEntry *lme, *_lme;
- struct Interrupt *irq;
-
- NewList((struct List *)&tmplist);
-
- Forbid();
-
- ITERATE_LIST(&SysBase->ex_MemHandlers, struct Interrupt *, irq) {
- if (lme = AllocVec(sizeof(struct LowMemoryEntry), MEMF_PUBLIC)) {
- lme->lme_Addr = irq;
-
- _snprintf(lme->lme_Address, sizeof(lme->lme_Address), "$%08lx", irq);
- stccpy(lme->lme_Name, nonetest(irq->is_Node.ln_Name), sizeof(lme->lme_Name));
- stccpy(lme->lme_Type, GetNodeType(irq->is_Node.ln_Type), sizeof(lme->lme_Type));
- _snprintf(lme->lme_Pri, sizeof(lme->lme_Pri), "%4ld", irq->is_Node.ln_Pri);
- _snprintf(lme->lme_Data, sizeof(lme->lme_Data), "$%08lx", irq->is_Data);
- if (points2ram((APTR)irq->is_Code)) {
- _snprintf(lme->lme_Code, sizeof(lme->lme_Code), MUIX_PH "$%08lx", irq->is_Code);
- } else {
- _snprintf(lme->lme_Code, sizeof(lme->lme_Code), "$%08lx", irq->is_Code);
- }
-
- AddTail((struct List *)&tmplist, (struct Node *)lme);
- }
- }
-
- Permit();
-
- ITERATE_CHANGING_LIST(&tmplist, struct LowMemoryEntry *, lme, _lme) {
- callback(lme, userData);
- FreeVec(lme);
- }
- }
- }
-
- static void UpdateCallback( struct LowMemoryEntry *lme,
- void *userData )
- {
- struct LowMemoryCallbackUserData *ud = (struct LowMemoryCallbackUserData *)userData;
-
- InsertBottomEntry(ud->ud_List, lme);
- ud->ud_Count++;
- }
-
- static void PrintCallback( struct LowMemoryEntry *lme,
- void *userData )
- {
- if (points2ram((APTR)lme->lme_Addr->is_Code)) {
- PrintFOneLine((BPTR)userData, " %s %-9s %4s %s %-9.9s %s\n", lme->lme_Address, lme->lme_Type, lme->lme_Pri, lme->lme_Data, lme->lme_Code + 2, lme->lme_Name);
- } else {
- PrintFOneLine((BPTR)userData, " %s %-9s %4s %s %-9.9s %s\n", lme->lme_Address, lme->lme_Type, lme->lme_Pri, lme->lme_Data, lme->lme_Code, lme->lme_Name);
- }
- }
-
- static void SendCallback( struct LowMemoryEntry *lme,
- void *userData )
- {
- SendEncodedEntry((UBYTE *)lme, sizeof(struct LowMemoryEntry));
- }
-
- static ULONG __saveds mNew( struct IClass *cl,
- Object *obj,
- struct opSet *msg )
- {
- APTR lowmemlist, lowmemtext, lowmemcount, updateButton, printButton, removeButton, priorityButton, exitButton;
-
- if (obj = (Object *)DoSuperNew(cl, obj,
- MUIA_HelpNode, LowMemoryText,
- MUIA_Window_ID, MakeID('L','O','W','M'),
- WindowContents, VGroup,
-
- Child, lowmemlist = MyNListviewObject(MakeID('L','M','L','V'), "BAR,BAR,BAR P=" MUIX_C ",BAR P=" MUIX_R ",BAR,BAR", &lowmemlist_con2hook, &lowmemlist_des2hook, &lowmemlist_dsp2hook, &lowmemlist_cmp2hook, TRUE),
- Child, MyBelowListview(&lowmemtext, &lowmemcount),
-
- Child, MyVSpace(4),
-
- Child, HGroup, MUIA_Group_SameSize, TRUE,
- Child, updateButton = MakeButton(txtUpdate),
- Child, printButton = MakeButton(txtPrint),
- Child, removeButton = MakeButton(txtRemove),
- Child, priorityButton = MakeButton(txtPriority),
- Child, exitButton = MakeButton(txtExit),
- End,
- End,
- TAG_MORE, msg->ops_AttrList))
- {
- struct LowMemoryWinData *lmwd = INST_DATA(cl, obj);
- APTR parent;
-
- lmwd->lmwd_LowMemoryList = lowmemlist;
- lmwd->lmwd_LowMemoryText = lowmemtext;
- lmwd->lmwd_LowMemoryCount = lowmemcount;
- lmwd->lmwd_RemoveButton = removeButton;
- lmwd->lmwd_PriorityButton = priorityButton;
-
- parent = (APTR)GetTagData(MUIA_Window_ParentWindow, (ULONG)NULL, msg->ops_AttrList);
-
- set(obj, MUIA_Window_Title, MyGetWindowTitle("LOWMEMORY", lmwd->lmwd_Title, sizeof(lmwd->lmwd_Title)));
- set(obj, MUIA_Window_ActiveObject, lowmemlist);
- set(removeButton, MUIA_Disabled, TRUE);
- set(priorityButton, MUIA_Disabled, TRUE);
-
- DoMethod(parent, MUIM_Window_AddChildWindow, obj);
- DoMethod(obj, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, MUIV_Notify_Application, 5, MUIM_Application_PushMethod, parent, 2, MUIM_Window_RemChildWindow, obj);
- DoMethod(lowmemlist, MUIM_Notify, MUIA_NList_Active, MUIV_EveryTime, obj, 1, MUIM_LowMemoryWin_ListChange);
- DoMethod(updateButton, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, MUIM_LowMemoryWin_Update);
- DoMethod(printButton, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, MUIM_LowMemoryWin_Print);
- DoMethod(removeButton, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, MUIM_LowMemoryWin_Remove);
- DoMethod(priorityButton, MUIM_Notify, MUIA_Pressed, FALSE, obj, 1, MUIM_LowMemoryWin_Priority);
- DoMethod(exitButton, MUIM_Notify, MUIA_Pressed, FALSE, obj, 3, MUIM_Set, MUIA_Window_CloseRequest, TRUE);
- }
-
- return (ULONG)obj;
- }
-
- static ULONG __saveds mDispose( struct IClass *cl,
- Object *obj,
- struct opSet *msg )
- {
- struct LowMemoryWinData *lmwd = INST_DATA(cl, obj);
-
- set(obj, MUIA_Window_Open, FALSE);
- DoMethod(lmwd->lmwd_LowMemoryList, MUIM_NList_Clear);
-
- return (DoSuperMethodA(cl, obj, msg));
- }
-
- static ULONG __saveds mUpdate( struct IClass *cl,
- Object *obj,
- Msg msg )
- {
- struct LowMemoryWinData *lmwd = INST_DATA(cl, obj);
- struct LowMemoryCallbackUserData ud;
-
- ApplicationSleep(TRUE);
- set(lmwd->lmwd_LowMemoryList, MUIA_NList_Quiet, TRUE);
- DoMethod(lmwd->lmwd_LowMemoryList, MUIM_NList_Clear);
-
- ud.ud_List = lmwd->lmwd_LowMemoryList;
- ud.ud_Count = 0;
-
- if (clientstate) {
- ReceiveList(UpdateCallback, &ud);
- } else {
- IterateList(UpdateCallback, &ud);
- }
-
- SetCountText(lmwd->lmwd_LowMemoryCount, ud.ud_Count);
- MySetContents(lmwd->lmwd_LowMemoryText, "");
-
- set(lmwd->lmwd_LowMemoryList, MUIA_NList_Quiet, FALSE);
- set(lmwd->lmwd_RemoveButton, MUIA_Disabled, TRUE);
- set(lmwd->lmwd_PriorityButton, MUIA_Disabled, TRUE);
- ApplicationSleep(FALSE);
-
- return 0;
- }
-
- static ULONG __saveds mPrint( struct IClass *cl,
- Object *obj,
- Msg msg )
- {
- PrintLowMemory(NULL);
-
- return 0;
- }
-
- static ULONG __saveds mRemove( struct IClass *cl,
- Object *obj,
- Msg msg )
- {
- struct LowMemoryWinData *lmwd = INST_DATA(cl, obj);
- struct LowMemoryEntry *lme;
-
- if (lme = (struct LowMemoryEntry *)GetActiveEntry(lmwd->lmwd_LowMemoryList)) {
- if (MyRequest(msgYesNo, msgWantToRemoveLowMemory, lme->lme_Name)) {
- MyDoCommand("RemoveLowMemory %s", lme->lme_Address);
- DoMethod(obj, MUIM_LowMemoryWin_Update);
- }
- }
-
- return 0;
- }
-
- static ULONG __saveds mPriority( struct IClass *cl,
- Object *obj,
- Msg msg )
- {
- struct LowMemoryWinData *lmwd = INST_DATA(cl, obj);
- struct LowMemoryEntry *lme;
-
- if (lme = (struct LowMemoryEntry *)GetActiveEntry(lmwd->lmwd_LowMemoryList)) {
- LONG pri;
-
- pri = atol(lme->lme_Pri);
- if (GetPriority(lme->lme_Name, &pri)) {
- if (MyDoCommand("SetPriority LOWMEMORY \"%s\" %ld", lme->lme_Name, pri)) {
- _snprintf(lme->lme_Pri, sizeof(lme->lme_Pri), "%4ld", pri);
- RedrawActiveEntry(lmwd->lmwd_LowMemoryList);
- }
- }
- }
-
- return 0;
- }
-
- static ULONG __saveds mListChange( struct IClass *cl,
- Object *obj,
- Msg msg )
- {
- struct LowMemoryWinData *lmwd = INST_DATA(cl, obj);
- struct LowMemoryEntry *lme;
-
- if (lme = (struct LowMemoryEntry *)GetActiveEntry(lmwd->lmwd_LowMemoryList)) {
- MySetContents(lmwd->lmwd_LowMemoryText, "%s \"%s\"", lme->lme_Address, lme->lme_Name);
- set(lmwd->lmwd_RemoveButton, MUIA_Disabled, FALSE);
- set(lmwd->lmwd_PriorityButton, MUIA_Disabled, FALSE);
- }
-
- return 0;
- }
-
- ULONG __asm __saveds LowMemoryWinDispatcher( register __a0 struct IClass *cl,
- register __a2 Object *obj,
- register __a1 Msg msg )
- {
- switch (msg->MethodID) {
- case OM_NEW: return (mNew(cl, obj, (APTR)msg));
- case OM_DISPOSE: return (mDispose(cl, obj, (APTR)msg));
- case MUIM_LowMemoryWin_Update: return (mUpdate(cl, obj, (APTR)msg));
- case MUIM_LowMemoryWin_Print: return (mPrint(cl, obj, (APTR)msg));
- case MUIM_LowMemoryWin_Remove: return (mRemove(cl, obj, (APTR)msg));
- case MUIM_LowMemoryWin_Priority: return (mPriority(cl, obj, (APTR)msg));
- case MUIM_LowMemoryWin_ListChange: return (mListChange(cl, obj, (APTR)msg));
- }
-
- return (DoSuperMethodA(cl, obj, msg));
- }
-
- void PrintLowMemory( char *filename )
- {
- BPTR handle;
-
- if (handle = HandlePrintStart(filename)) {
- PrintFOneLine(handle, "\n Address Type Pri Data Code Name\n\n");
- IterateList(PrintCallback, (void *)handle);
- }
-
- HandlePrintStop();
- }
-
- void SendLowMemory( void )
- {
- IterateList(SendCallback, NULL);
- }
-
-